import 'package:flutter/cupertino.dart';
import 'package:thinking/config/_.dart';
import 'package:thinking/utils/_.dart';
import 'package:thinking/entity/_.dart';

class CountryEditItem extends StatefulWidget{

  final CountryData data;
  final bool isFocus;
  final Function callBack;

  CountryEditItem({required this.data,required this.isFocus,required this.callBack});

  @override
  _CountryEditItem createState() => _CountryEditItem(data:data,isFocus: isFocus,callBack: callBack);

}

class _CountryEditItem extends State<CountryEditItem>{

    ClickModel clickModel = ClickModel.Ordinary;

    CountryData data;
    bool isFocus;
   final Function callBack;

  _CountryEditItem({required this.data,required this.isFocus,required this.callBack});

  @override
  void initState() {
    super.initState();
    clickModel = isFocus?ClickModel.Focus:ClickModel.Ordinary;

  }

  @override
  void didUpdateWidget(covariant CountryEditItem oldWidget) {
    super.didUpdateWidget(oldWidget);
    if(oldWidget.isFocus == true && widget.isFocus ==false){
      setState(() {
        this.clickModel = ClickModel.Ordinary;
      });
    }

  }

  @override
  void dispose() {
    super.dispose();
  }

    @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: (){
        setState(() {
          clickModel = ClickModel.Focus ==clickModel?ClickModel.Ordinary:ClickModel.Focus ;
          callBack(clickModel:clickModel,countryId:data.id);
        });
      },

      child: Container(
          padding: EdgeInsets.all(5),
          height: Screen.setHeight(40),
          width: Screen.setWidth(100),
          decoration: BoxDecoration(
              color: clickModel == ClickModel.Ordinary?ColorConfig.LineColor:ColorConfig.WhiteBackColor,
              borderRadius: clickModel == ClickModel.Ordinary?null:BorderRadius.all(Radius.circular(5)),
              border: clickModel == ClickModel.Ordinary?null:Border.all(color: ColorConfig.ThemeColor,width: 1),
          ),
          child: Center(
            child: Text(
              data.name!,
              style: TextStyle(
                  color: clickModel == ClickModel.Ordinary?ColorConfig.BlackBackColor:ColorConfig.ThemeColor),
            ),
          )
      ),
    );
  }

}

enum ClickModel  {Focus,Ordinary}